package com.nantai.jiafang.nantaijiafang.nt5s.fragments;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.nantai.jiafang.nantaijiafang.Data;
import com.nantai.jiafang.nantaijiafang.R;
import com.nantai.jiafang.nantaijiafang.RecyclerItemClickListener;
import com.nantai.jiafang.nantaijiafang.databinding.FragmentUperror1Binding;
import com.nantai.jiafang.nantaijiafang.nt5s.adapter.UperrorsearchAdapter;
import com.nantai.jiafang.nantaijiafang.nt5s.bean.Uperror_Item;
import com.nantai.jiafang.nantaijiafang.nt5s.fragments.ViewHolder.Holder_Fragment1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/25.
 */

public class UpErrorfragment1 extends Fragment {
    private FragmentUperror1Binding binding;
    private Holder_Fragment1 holder_fragment1;
    private UperrorsearchAdapter uperrorsearchAdapter;
    public static List<Uperror_Item> uperror_itemArrayList=new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //View view=inflater.inflate(R.layout.fragment_uperror1,container,false);
        binding= DataBindingUtil.inflate(inflater,R.layout.fragment_uperror1,container,false);
        holder_fragment1=new Holder_Fragment1(getActivity().getApplicationContext());
        holder_fragment1.init(new Holder_Fragment1.Getdata() {
            @Override
            public void data(ArrayList<Uperror_Item> uperror_items) {
                binding.searchList.setLayoutManager(new LinearLayoutManager(getContext().getApplicationContext(), LinearLayoutManager.VERTICAL, false));
                uperrorsearchAdapter=new UperrorsearchAdapter(getContext().getApplicationContext(), uperror_items);
                uperror_itemArrayList=uperror_items;
                binding.searchList.setAdapter(uperrorsearchAdapter);
            }
        });
        binding.addUperror.setOnClickListener(v->{
            Data.MODE=-1;
            Data.uperror_item=null;
                getFragmentManager().beginTransaction()
                        .addToBackStack(null)					//添加返回键返回
                        .setCustomAnimations(R.anim.in_from_left,R.anim.in_from_right,R.anim.out_from_left,R.anim.out_from_right)
                        .add(R.id.uperror_search,new UpErrorfragment_Add(),"fragment1")
                        .commit();
        });
        binding.searchList.addOnItemTouchListener(new RecyclerItemClickListener(getContext(), new RecyclerItemClickListener.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                    Data.MODE = position;
                    Data.uperror_item = uperror_itemArrayList.get(position);
                    getFragmentManager().beginTransaction()
                            .addToBackStack(null)                    //添加返回键返回
                            .setCustomAnimations(R.anim.in_from_left, R.anim.in_from_right, R.anim.out_from_left, R.anim.out_from_right)
                            .add(R.id.uperror_search, new UpErrorfragment_Add(), "fragment1")
                            .commit();
            }
            @Override
            public void onLongClick(View view, int posotion) {

            }
        }));
        return binding.getRoot();
    }


    /*      "ProDesc":"1",问题描述
        "Cause":"2",调查原因
        "Analysis":"3",问题分析
        "Solve":"4",处理结果
        "ISOK":"1",是否执行完成
        "UploadDate":"2017/10/26 14:45:54",投诉时间
        "UploadUser":"系统管理员",投诉人
        "ComplaintPerson":"admin",监察人        "SolveDate":"2017/10/26 0:00:00"处理时间*/
}
